package cn.tk.model.pojo.mr.flow;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Objects;

/**
 * Created by denglw on 2021/7/16.<br/>
 * Desc: 条件
 */
@Data @NoArgsConstructor
public class ConditionDTO {

    /**
     * 条件id
     */
    private Long conditionId;

    /**
     * 节点id
     */
    private Long nodeId;

    /**
     * 条件类型 : 1意图 2实体 3变量
     */
    private Integer type;

    /**
     * 匹配的意图id
     */
    private Long intentId;

    /**
     * 匹配的意图编码
     */
    private String intentCode;

    /**
     * 匹配的实体id
     */
    private Long entityId;

    /**
     * 匹配的实体编码
     */
    private String entityCode;

    /**
     * 实体值匹配规则（type=3）：1等于 2不等于 3大于 4小于 5大于等于 6小于等于
     */
    private Integer entityValueRule;

    /**
     * 匹配的实体值
     */
    private String entityValue;

    /**
     * 匹配的变量id
     */
    private Long variableId;

    /**
     * 匹配的变量英文名
     */
    private String variableEnName;

    /**
     * 变量匹配规则（type=4）：1等于 2不等于 3大于 4小于 5大于等于 6小于等于
     */
    private Integer variableRule;

    /**
     * 匹配的变量值
     */
    private String variableValue;

    @SuppressWarnings("unused")
    public ConditionDTO(Long conditionId, Long nodeId, Integer type, Long intentId,
                        Long entityId, Integer entityValueRule, String entityValue,
                        Long variableId, Integer variableRule, String variableValue) {
        this.conditionId = conditionId;
        this.nodeId = nodeId;
        this.type = type;
        this.intentId = intentId;
        this.entityId = entityId;
        this.entityValueRule = entityValueRule;
        this.entityValue = entityValue;
        this.variableId = variableId;
        this.variableRule = variableRule;
        this.variableValue = variableValue;
    }

    /**
     * 将实例的实体匹配规则转义为运算符号.<br/>
     * @return 运算符
     */
    public String entityValueRule2Symbol() {
        if (entityValueRule == null) {
            return "";
        }
        String[] symbols = {"===", "!==", ">", "<", ">=", "<="};
        if (entityValueRule >=1 && entityValueRule <= 6) {
            return symbols[entityValueRule - 1];
        }
        return "";
    }

    public boolean isIntentType() {
        return Objects.equals(type, 1);
    }

    public boolean isEntityType() {
        return Objects.equals(type, 2);
    }
}
